package com.webull.information.center.carwler.common.json.unit;

import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import org.apache.commons.lang3.StringUtils;

import com.webull.framework.util.UtilDate;

/**
 * retures json 工具类
 * 
 * @author shimingjun
 * @date 2016年8月8日 上午11:38:46
 * @version 1.0
 * @since JDK 1.8
 */
public class News_1_RetrieveHeadlineML_1 {
	public final static String restUrl = "http://api.trkd.thomsonreuters.com/api/News/News.svc/REST/News_1/RetrieveHeadlineML_1";
	// "http://api.rkd.reuters.com/api/News/News.svc/REST/News_1/RetrieveHeadlineML_1";



	public static String getRicRequestJson(int maxCount, String nRic) {
		String request_json = "{\n" + 
				"    \"RetrieveHeadlineML_Request_1\":{\n" + 
				"        \"HeadlineMLRequest\":{\n" + 
				"            \"MaxCount\":{0},\n" + 
				"            \"Filter\":[\n" + 
				"                {\n" + 
				"                    \"MetaDataConstraint\":{\n" + 
				"                        \"Value\":{\n" + 
				"                            \"Text\":\"{1}\"\n" + 
				"                        },\n" + 
				"                        \"class\":\"companies\"\n" + 
				"                    }\n" + 
				"                },\n" + 
				"                {\n" + 
				"                    \"MetaDataConstraint\":{\n" + 
				"                        \"Or\":{\n" + 
				"                            \"Value_typehint\":[\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\"\n" + 
				"                            ],\n" + 
				"                            \"Value\":[\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"en\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"zh\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"it\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"ja\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"fr\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"de\"\n" + 
				"                                }\n" + 
				"                            ]\n" + 
				"                        },\n" + 
				"                        \"class\":\"language\"\n" + 
				"                    }\n" + 
				"                }\n" + 
				"            ]\n" + 
				"        }\n" + 
				"    }\n" + 
				"}";
		request_json = StringUtils.replace(request_json, "{0}", maxCount + "");
		request_json = StringUtils.replace(request_json, "{1}", nRic);

		return request_json;
	}

	
	
	

	public static String getCodeRequestJson2(int maxCount, String code) {
		String request_json = "{\n" + 
				"    \"RetrieveHeadlineML_Request_1\":{\n" + 
				"        \"HeadlineMLRequest\":{\n" + 
				"            \"MaxCount\":{0},\n" + 
				"            \"Filter\":[\n" + 
				"                {\n" + 
				"                    \"MetaDataConstraint\":{\n" + 
				"                        \"Value\":{\n" + 
				"                            \"Text\":\"{1}\"\n" + 
				"                        },\n" + 
				"                        \"class\":\"any\"\n" + 
				"                    }\n" + 
				"                },\n" + 
				"                {\n" + 
				"                    \"MetaDataConstraint\":{\n" + 
				"                        \"Or\":{\n" + 
				"                            \"Value_typehint\":[\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\"\n" + 
				"                            ],\n" + 
				"                            \"Value\":[\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"en\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"zh\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"it\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"ja\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"fr\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"de\"\n" + 
				"                                }\n" + 
				"                            ]\n" + 
				"                        },\n" + 
				"                        \"class\":\"language\"\n" + 
				"                    }\n" + 
				"                }\n" + 
				"            ]\n" + 
				"        }\n" + 
				"    }\n" + 
				"}\n" + 
				"";
		request_json = StringUtils.replace(request_json, "{0}", maxCount + "");
		request_json = StringUtils.replace(request_json, "{1}", code);
		return request_json;
	}

	public static String getCodeRequestJsonZH(int maxCount, String code, boolean tradit) {
		String request_json = "{                                                                          "
				+ "    \"RetrieveHeadlineML_Request_1\":{                                                 "
				+ "        \"HeadlineMLRequest\":{                                                        "
				+ "            \"MaxCount\":{0},                                                          "
				+ "            \"Filter\":[                                                               "
				+ "                {                                                                      "
				+ "                    \"And\":{                                                          "
				+ "                        \"MetaDataConstraint_typehint\":[                              "
				// + " \"MetaDataConstraint\", "
				+ "                            \"MetaDataConstraint\",                                    "
				+ "                            \"MetaDataConstraint\"                                     "
				+ "                        ],                                                             "
				+ "                        \"MetaDataConstraint\":[                                       "
				+ "                            {                                                          "
				+ "                                \"class\":\"any\",                               	  "
				+ "                                \"Value\":{                                            "
				+ "                                    \"Text\":\"{1}\"                                   "
				+ "                                }                                                      "
				+ "                            },                                                         "
				// + " { "
				// + " \"class\":\"topics\", "
				// + " \"Value\":{ "
				// + " \"Text\":\"LZS\" "
				// + " } "
				// + " }, "
				+ "                            {                                                          "
				+ "                                \"class\":\"language\",                                "
				+ "                                \"Value\":{                                            "
				+ "                                    \"Text\":\"zh\"                                    "
				+ "                                }                                                      "
				+ "                            }                                                          "
				+ "                        ]                                                              "
				+ "                    }                                                                  "
				+ "                }                                                                      "
				+ "            ]                                                                          "
				+ "        }                                                                             "
				+ "    }                                                                                  "
				+ "}                                                                                      ";
		request_json = StringUtils.replace(request_json, "{0}", maxCount + "");
		request_json = StringUtils.replace(request_json, "{1}", code);
		if (tradit) request_json = StringUtils.replace(request_json, "\"LZS\"", "\"LZT\"");
		return request_json;
	}

	public static String getHomePageTopicRequestJson(String rtlang) {
		String request_json = "{																																	"
				+ "    \"RetrieveHeadlineML_Request_1\":{                                    "
				+ "        \"HeadlineMLRequest\":{                                           "
				+ "            \"MaxCount\":25,                                              "
				+ "            \"Filter\":[                                                  "
				+ "                {                                                         "
				+ "                    \"And\":{                                             "
				+ "                        \"Or_typehint\":[                                 "
				+ "                            \"Or\",                                       "
				+ "                            \"MetaDataConstraint\",                       "
				+ "                            \"MetaDataConstraint\",                       "
				+ "                            \"Or\"                                        "
				+ "                        ],                                                "
				+ "                        \"Or\":[                                          "
				+ "                            {                                             "
				+ "                                \"MetaDataConstraint_typehint\":[         "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\"                "
				+ "                                ],                                        "
				+ "                                \"MetaDataConstraint\":[                  "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"CEN\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"INT\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"FED\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"ECI\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"G7\"               "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"DBT\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"IMF\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"FRX\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"MMT\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"EZ\"               "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"ECB\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"BOJ\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"topics\"              "
				+ "                                    }                                     "
				+ "                                ]                                         "
				+ "                            },                                            "
				+ "                            {                                             "
				+ "                                \"Value\":{                               "
				+ "                                    \"Text\":\"RTRS\"                     "
				+ "                                },                                        "
				+ "                                \"class\":\"attribution\"                 "
				+ "                            },                                            "
				+ "                            {                                             "
				+ "                                \"Value\":{                               "
				+ "                                    \"Text\":\"{rtlang}\"                      "
				+ "                                },                                        "
				+ "                                \"class\":\"language\"                    "
				+ "                            },                                            "
				+ "                            {                                             "
				+ "                                \"MetaDataConstraint_typehint\":[         "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\",               "
				+ "                                    \"MetaDataConstraint\"                "
				+ "                                ],                                        "
				+ "                                \"MetaDataConstraint\":[                  "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"DNP\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"products\"            "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"RNP\"              "
				+ "                                        },                                "
				+ "                                        \"class\":\"products\"            "
				+ "                                    },                                    "
				+ "                                    {                                     "
				+ "                                        \"Value\":{                       "
				+ "                                            \"Text\":\"M\"                "
				+ "                                        },                                "
				+ "                                        \"class\":\"products\"            "
				+ "                                    }                                     "
				+ "                                ]                                         "
				+ "                            }                                             "
				+ "                        ]                                                 "
				+ "                    }                                                     "
				+ "                }                                                         "
				+ "            ]                                                             "
				+ "        }                                                                 "
				+ "    }                                                                     "
				+ "}                                                                         ";
		return StringUtils.replaceOnce(request_json, "{rtlang}", rtlang);

	}

	public static String getHomePageReportRequestJson(String rtlang) {
		String request_json = "{                                                                                                        "
				+ "    \"RetrieveHeadlineML_Request_1\":{                                                                  "
				+ "        \"HeadlineMLRequest\":{                                                                         "
				+ "            \"MaxCount\":25,                                                                            "
				+ "            \"Filter\":[                                                                                "
				+ "                {                                                                                       "
				+ "                    \"And\":{                                                                           "
				+ "                        \"Or_typehint\":[                                                               "
				+ "                            \"Or\",                                                                     "
				+ "                            \"MetaDataConstraint\"                                                      "
				+ "                        ],                                                                              "
				+ "                        \"Or\":[                                                                        "
				+ "                            {                                                                           "
				+ "                                \"MetaDataConstraint_typehint\":[                                       "
				+ "                                    \"MetaDataConstraint\",                                             "
				+ "                                    \"MetaDataConstraint\",                                             "
				+ "                                    \"MetaDataConstraint\",                                             "
				+ "                                    \"MetaDataConstraint\",                                             "
				+ "                                    \"MetaDataConstraint\",                                             "
				+ "                                    \"MetaDataConstraint\"                                              "
				+ "                                ],                                                                      "
				+ "                                \"MetaDataConstraint\":[                                                "
				+ "                                    {                                                                   "
				+ "                                        \"Value\":{                                                     "
				+ "                                            \"Text\":\"AUD/CN\"                                         "
				+ "                                        },                                                              "
				+ "                                        \"class\":\"any\"                                               "
				+ "                                    },                                                                  "
				+ "                                    {                                                                   "
				+ "                                        \"Value\":{                                                     "
				+ "                                            \"Text\":\"EMRG/SGCN\"                                      "
				+ "                                        },                                                              "
				+ "                                        \"class\":\"any\"                                               "
				+ "                                    },                                                                  "
				+ "                                    {                                                                   "
				+ "                                        \"Value\":{                                                     "
				+ "                                            \"Text\":\"KRW/CN\"                                         "
				+ "                                        },                                                              "
				+ "                                        \"class\":\"any\"                                               "
				+ "                                    },                                                                  "
				+ "                                    {                                                                   "
				+ "                                        \"Value\":{                                                     "
				+ "                                            \"Text\":\"CHF/CN\"                                         "
				+ "                                        },                                                              "
				+ "                                        \"class\":\"any\"                                               "
				+ "                                    },                                                                  "
				+ "                                    {                                                                   "
				+ "                                        \"Value\":{                                                     "
				+ "                                            \"Text\":\"TWD/CN\"                                         "
				+ "                                        },                                                              "
				+ "                                        \"class\":\"any\"                                               "
				+ "                                    },                                                                  "
				+ "                                    {                                                                   "
				+ "                                        \"Value\":{                                                     "
				+ "                                            \"Text\":\"GBP/CN\"                                         "
				+ "                                        },                                                              "
				+ "                                        \"class\":\"any\"                                               "
				+ "                                    }                                                                   "
				+ "                                ]                                                                       "
				+ "                            },                                                                          "
				+ "                            {                                                                           "
				+ "                                \"Value\":{                                                             "
				+ "                                    \"Text\":\"{rtlang}\"                                                     "
				+ "                                },                                                                      "
				+ "                                \"class\":\"language\"                                                  "
				+ "                            }                                                                           "
				+ "                        ]                                                                               "
				+ "                    }                                                                                   "
				+ "                }                                                                                       "
				+ "            ]                                                                                           "
				+ "        }                                                                                               "
				+ "    }                                                                                                   "
				+ "}                                                                                                       ";
		return StringUtils.replaceOnce(request_json, "{rtlang}", rtlang);
	}
	
	
	public static String getRegionLangsRequestJson(String region, Integer maxCount, Date startTime, Date endTime) {
		final String json = "{\n" + 
				"    \"RetrieveHeadlineML_Request_1\":{\n" + 
				"        \"HeadlineMLRequest\":{\n" + 
				"            \"MaxCount\":{maxCount},\n" + 
				"            \"StartTime\":\"{startTime}\",\n" + 
				"            \"EndTime\":\"{endTime}\",\n" + 
				"            \"Filter\":[\n" + 
				"                {\n" + 
				"                    \"MetaDataConstraint\":{\n" + 
				"                        \"Value\":{\n" + 
				"                            \"Text\":\"{region}\"\n" + 
				"                        },\n" + 
				"                        \"class\":\"topics\"\n" + 
				"                    }\n" + 
				"                },\n" + 
				"                {\n" + 
				"                    \"MetaDataConstraint\":{\n" + 
				"                        \"Value\":{\n" + 
				"                            \"Text\":\"CMPNY\"\n" + 
				"                        },\n" + 
				"                        \"class\":\"topics\"\n" + 
				"                    }\n" + 
				"                },\n" + 
				"                {\n" + 
				"                    \"MetaDataConstraint\":{\n" + 
				"                        \"Or\":{\n" + 
				"                            \"Value_typehint\":[\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\",\n" + 
				"                                \"Value\"\n" + 
				"                            ],\n" + 
				"                            \"Value\":[\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"en\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"zh\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"fr\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"de\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"ja\"\n" + 
				"                                },\n" + 
				"                                {\n" + 
				"                                    \"Text\":\"it\"\n" + 
				"                                }\n" + 
				"                            ]\n" + 
				"                        },\n" + 
				"                        \"class\":\"language\"\n" + 
				"                    }\n" + 
				"                }\n" + 
				"            ]\n" + 
				"        }\n" + 
				"    }\n" + 
				"}";
		String r_json = StringUtils.replaceOnce(json, "{region}", region);
		r_json = StringUtils.replaceOnce(r_json, "{maxCount}", maxCount + "");
		// "2017-08-10T01:00:00"
		final String format = "yyyy-MM-dd'T'HH:mm:ss";
		r_json = StringUtils.replaceOnce(r_json, "{startTime}",
				UtilDate.format(startTime, Locale.ENGLISH, TimeZone.getTimeZone("GMT"), format));
		r_json = StringUtils.replaceOnce(r_json, "{endTime}",
				UtilDate.format(endTime, Locale.ENGLISH, TimeZone.getTimeZone("GMT"), format));
		return r_json;
	}

	public static void main(String[] args) {
		System.out.println(getRicRequestJson(99, "aapl.o"));
	}
}
